package de.au.fi.imp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import de.au.fi.controller.SearchResultController;
import de.au.fi.domain.Stock;
import de.au.fi.manager.StockManager;


public class ImportStockWorker extends Thread {

	SearchResultController searchResultController;
	List<String> wknList;
	List<String> importedWkns = new ArrayList<String>();
	List<String> notImportedWkns = new ArrayList<String>();
	public boolean running = false;
	OnVistaImporter importStock = new OnVistaImporter();
	
	public ImportStockWorker(List<String> wknList, SearchResultController searchResultController) {
		this.searchResultController = searchResultController;
		this.wknList = wknList;
	}

	@Override
	public void run() {
		running = true;
		List<Stock> stocks = new ArrayList<Stock>();
		for(String wkn : wknList)
		{
			Stock stock = new Stock();
			stock.setWkn(wkn);
			stock = importStock.importStocksFromOnVista(stock).get(0);
			if(stock != null)
			{
				importedWkns.add(wkn);
				stocks.add(stock);
			}
			else notImportedWkns.add(wkn);
		}
		if(searchResultController != null)
			this.searchResultController.setStocks(stocks);
		running = false;
	}

	public List<String> getWknList() {
		return wknList;
	}

	public List<String> getImportedWkns() {
		return importedWkns;
	}

	public List<String> getNotImportedWkns() {
		return notImportedWkns;
	}

	public boolean isRunning() {
		return running;
	}

	public int getWknListSize()
	{
		if(wknList!=null)return wknList.size();
		return 0;
	}
	
	public int getImportedWknListSize()
	{
		if(importedWkns!=null)return importedWkns.size();
		return 0;
	}
	
	public int getnotImportedWknListSize()
	{
		if(notImportedWkns!=null)return notImportedWkns.size();
		return 0;
	}
	
	

	
	
}
